import type { Component } from 'vue'

import {
  createRouter,
  createWebHistory,
  RouteRecordRaw,
} from 'vue-router';

import componentsMap from '@/views/init';
// 获取所有示例组件放置到路由里面
let routerPaths: Array<RouteRecordRaw> = Object.keys(componentsMap).map((key: string) => {
  let component: Component = componentsMap[key]
  let path = component.name
  let labelName = component?.labelName
  return {
    path: `/demo/${path}`,
    name: labelName,
    component: componentsMap[key]
  }
})

let homeRouter: RouteRecordRaw = {
  path: '/',
  name: 'home',
  component: () => import('@/views/home/index.vue'),
}

const routes: Array<RouteRecordRaw> = [
  homeRouter,
  ...routerPaths
]


export const router = createRouter({
  history: createWebHistory(),
  routes,
});